/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#include "MkSampleGbDevice.h"
#include "MkEvent/MkTimer.h"
#include "MkEvent/MkEventPool.h"
#include "MkUtil/MkUtil.h"
#include "MkUtil/MkLog.h"
#include <signal.h>


CMkTimer *g_Timer;
int main(int argc, char ** argv)
{
#ifdef _WIN32
    WSADATA WSAData;
    WSAStartup(0x101, &WSAData);
#else
    signal(SIGPIPE, SIG_IGN);  //ignore sigpipe
#endif
    MkLogChangeLevel(LOG_DEBUG);
    CMkEventPool Pool;
    CMkTimer Timer;
    g_Timer = &Timer;
    Pool.Start(1);
    CMkSampleGbDevice GbDevice(&Pool, &Timer);

    signal(SIGINT, [](int sig) {
        if (SIGINT == sig) {
            g_Timer->LoopBreak();
        }
    });// set exit  signal
    MkGbStartParam Param;
    Param.LocalHost = "0.0.0.0";
    Param.LocalPort = 5080;
    Param.SipId = "34020000001320000001";
    Param.SipRealm = "3402000000";
    GbDevice.StartDevice(Param);
    GbDevice.SetServerInfo("34020000002000000001", "3400000000", "192.168.100.119", 5060, FALSE);
    //GbDevice.SetServerInfo("34020000002000000001", "3402000000", "192.168.0.24", 5060, TRUE);
    GbDevice.SetLocalInfo("34020000001320000001", "12345678", 3600, 5, 3);
    MkString DelaySession;
    Timer.AddDelayer([]() {}, 1000, DelaySession);
    Timer.Dispatch();
    Pool.Stop();
    GbDevice.Stop();
#ifdef _WIN32
    WSACleanup();
#endif
    printf("end\n");
    return 1;
}